package tw.com.book.componet;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommonUtils {
	private static final String TAG = CommonUtils.class.getSimpleName();

	public static String yyymmddFormat = "yyyyMMdd";
	public static String ddFormat = "dd";
	public static String YEAR_MON_FORMAT="yyyy/MM";

	public static String yyyFormat = "yyyy";

	public static String mmFormat = "MM";

	public static String timeFormate = "hhmmss";

	private static SimpleDateFormat DATE_SDF_TABLE = new SimpleDateFormat(
			yyymmddFormat);

	private static SimpleDateFormat dd_SDF_TABLE = new SimpleDateFormat(
			ddFormat);

	private static SimpleDateFormat yy_SDF_TABLE = new SimpleDateFormat(
			yyyFormat);

	private static SimpleDateFormat mm_SDF_TABLE = new SimpleDateFormat(
			mmFormat);
	
	
	public static SimpleDateFormat YYMM_SDF_TABLE = new SimpleDateFormat(
			mmFormat);

	public static Date getDateAsDate(String yyymmdd) {
		try {
			return DATE_SDF_TABLE.parse(yyymmdd);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

	public static String getDate(String yyymmdd) {
		try {
			return getDate(DATE_SDF_TABLE.parse(yyymmdd));
		} catch (Exception e) {
	
			return yyymmdd;
		}

	}

	
	public static String getTime() {
		return new SimpleDateFormat(timeFormate).format(new Date());

	}

	/**
	 * Gets the date.
	 * 
	 * @param yyyymmdd
	 *            the yyyymmdd
	 * @return the date
	 */
	public static String getDate() {
		String out = "";
		try {

			out = DATE_SDF_TABLE.format(new Date());

		} catch (Exception e) {
			e.printStackTrace();
		}
		return out;

	}

	public static String getMonth() {
		String out = "";
		try {

			out = mm_SDF_TABLE.format(new Date());

		} catch (Exception e) {
			e.printStackTrace();
		}
		return out;
	}

	public static String getDateDay() {
		String out = "";
		try {

			out = dd_SDF_TABLE.format(new Date());

		} catch (Exception e) {
			e.printStackTrace();
		}
		return out;
	}

	public static String getYear() {
		String out = "";
		try {

			out = yy_SDF_TABLE.format(new Date());

		} catch (Exception e) {
			e.printStackTrace();
		}
		return out;
	}

	public static String getDate(Date date) {
		String out = "";
		try {

			out = DATE_SDF_TABLE.format(date);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return out;
	}

}
